package com.love.dynamic;

import java.util.Arrays;

public class MinMoney {


    public static int MAX = 366;

    public static int[] dp = new int[MAX];

    private static int[] duration = {1,7,30};

    public static int minCost(int[] days, int[] costs){
        int n =  days.length;
        Arrays.fill(dp,0,n+1,Integer.MAX_VALUE);
        dp[n] = 0;
        for (int i = n - 1; i >= 0; i--){
            for (int k = 0, j = i; k < 3; k++ ){
                while (j < days.length && days[i] + duration[k] > days[j]){
                    j++;
                }
                dp[i] = Math.min(dp[i],costs[k] + dp[j] );
            }
        }

        return dp[0];
    }


    public static void main(String[] args) {
        int[] days = {1,4,6,7,8,20};
        int[] costs = {2,7,15};
        int c = minCost(days, costs);
        System.out.println(c);

    }

}
